<%--
  Created by IntelliJ IDEA.
  User: asus
  Date: 2017/6/22
  Time: 20:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.min.js"></script>
    <!-- 引入EasyUI -->
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.easyui.min.js"></script>
    <!-- 引入EasyUI的中文国际化js，让EasyUI支持中文 -->
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/easyui-lang-zh_CN.js"></script>
    <!--
    <script  type="text/javascript" src="scripts/index.js"></script>
  -->
    <!-- 引入EasyUI的样式文件-->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/easyui/themes/default/easyui.css" type="text/css"/>
    <!-- 引入EasyUI的图标样式文件-->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/easyui/themes/icon.css" type="text/css"/>
</head>
<body>
<table id="group_list_dg"></table>
</body>
<script>
    var UrlConfig = {
        SysGroupList: '<%=request.getContextPath() %>/user/list',
        SysGroupAdd: '<%=request.getContextPath() %>/user/addEditUser',
        SysGroupDelete: '<%=request.getContextPath() %>/user/deleteUser',
    };
    $(function () {
        $('#group_list_dg').datagrid({
            url: UrlConfig.SysGroupList,
            striped: true,					//隔行变色特性
            loadMsg: '数据正在加载,请耐心的等待...',
            singleSelect: true,
            rownumbers: true,
            fit: true,
            fitColumns: true,
            pagination: true,
            pageSize: 10,
            pageList: [5, 10, 15, 20, 50],
            toolbar: [
                {
                    text: '新增用户',
                    iconCls: 'icon-add',
                    handler: addUser
                },
                {
                    text: '删除用户',
                    iconCls: 'icon-remove',
                    handler: deleteUser
                },
                {
                    text: '保存',
                    iconCls: 'icon-save',
                    handler: save
                }
            ],
            columns: [[
                {
                    field: 'id',
                    title: '编号',
                    width: 60,
                },
                {
                    field: 'name',//field字段必须，为空也得写上，否则宽度为5px
                    title: '姓名',
                    width: 100,
                    editor: {
                        type: 'text',
                        options: {
                            required: true,
                        }
                    },

                },
                {
                    field: 'pwd',
                    title: '密码',
                    width: 50,
                    editor: {
                        type: 'passwordbox',
                        options: {
                            required: true,
                        }
                    },
                },
            ]],
            //在endEdit后自动触发检验是否符合validate才会执行
            onAfterEdit:function(rowIndex,rowData,changes){
                var inserted=$('#group_list_dg').datagrid('getChanges','inserted');
                var updated=$('#dg3_1').datagrid('getChanges','updated');
                //新增用户
                if(inserted.length>0){
                    $.ajax({
                        url: host+'department/create',
                        type: 'POST',
                        dataType: 'json',
                        data: {
                            name:inserted[0].name,
                        },
                    })
                        .done(function(data) {
                            console.log(data);
                            if(data.status==200){
                                $('#dg3_1').datagrid('loaded');
                                $('#dg3_1').datagrid('load');

                                $.messager.show({
                                    title:'提示',
                                    msg:"您已成功添加",
                                });
                                tb3_1.editRow=undefined;
                            }
                        });
                }
        },
    });
    function addUser() {
        $('#group_list_dg').datagrid('beginEdit', 0);
    }
    function deleteUser() {

    }
    function save() {
        $('#group_list_dg').datagrid('endEdit', 0);
    }
</script>
</html>
